<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<jsp:include page="../../common/header.jsp" />

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html>
<head>
<script type="text/javascript">
//返回到点击子菜单出现的列表
function back(id){
	$("#menupur_form").attr("action","<%=request.getContextPath()%>/sys/menu/list");
	$("#menupur_form").submit();
}

//新增或编辑页面--子菜单:权限
function toEditPurview(id){
	$("#to_form").attr("action","<%=request.getContextPath()%>/sys/menu-purview/form")
	$("#to_form_menuid").val(id);
	$("#to_form").submit();
}

//删除-子菜单:权限
function delPurviews(id,spurname){
	bootbox.dialog({
		message : "<spring:message code="sure you want to delete"></spring:message>"+spurname+"<spring:message code="what"></spring:message>",
		title : "<spring:message code="delete the submenu"></spring:message>",
		buttons : {
			confirm : {
				label : '<spring:message code="sure to delete"></spring:message>',
				className : "btn red btn-ok",
				callback : function() {
					$.ajax({
						type : "GET",
						url : "<%=request.getContextPath()%>/sys/menu-purview/del?id="+id,
						dataType : 'text',
						async : false,
						success : function(data) {
							if(data=="success"){
								noty({layout: 'top',text: "<spring:message code="delete the submenu success"></spring:message>！",type: 'success', timeout: 2000 });
								setTimeout(function(){window.location.reload();}, 1000);
							}else{
								noty({layout: 'top',text: "<spring:message code="delete the submenu failure"></spring:message>！",type: 'error', timeout: 2000 });
							}
						},
						error : function(data, status) {
							noty({layout: 'top',text: "<spring:message code="error"></spring:message>！",type: 'error', timeout: 2000 });
						}
					});
				}
			},
			cancel : {
				label : "<spring:message code="cancel"></spring:message>",
				className : "btn btn-danger"
			}
		}
	});
}

//分页
function toListPage(pageIndex){
	$("#menupur_form").attr("action","<%=request.getContextPath() %>/sys/menu-purview/list");
	$("#iDisplayStart").val(pageIndex);
	$("#menupur_form").submit();
}
</script>

</head>
<body class="page-header-fixed page-full-width">



		<form id="menupur_form"
			action="<%=request.getContextPath() %>/sys/menu-purview/list" method="post">
			<input type="hidden" name="parentid" id="hiddenId" value="${ menParentId}"></input>
			<input type="hidden" name="purid" id="puridId" value="${menuId }"></input> 
			
			<input type="hidden" name="spurname" id="spurnameId"></input>
			<input type="hidden" name="iDisplayStart" id="iDisplayStart" value=${list.currentPage } />
			<div class="page-content">


				<!-- BEGIN PAGE CONTAINER-->

				<div class="container-fluid">

					<!-- BEGIN PAGE HEADER-->
					<p></p>
					<div class="row-fluid">
						<div class="span12">



							<div class="row-fluid">
								<c:if test="${menuId!=null }">
									<div class="portlet-title">

										<div class="caption">
											<i class="icon-globe"></i>${menu.sname}-权限列表 &nbsp;&nbsp; <a
												href="#" onclick="back(${parentid});" class="btn mini gray"><spring:message
													code="btn.common.back"></spring:message></a>

										</div>
									</div>
								</c:if>

								<div class="portlet-body">

									<div class="clearfix">

										<p class="pull-left">

											<a href="#" onclick="toEditPurview(null);" class="btn blue">

												<spring:message code="btn.common.add.purview"></spring:message><i
												class="icon-plus"></i>

											</a>
										</p>
									</div>

									<table class="table table-striped table-bordered table-hover"
										id="pur_grid">
										<thead>
											<tr>
												<th><spring:message code="purview name"></spring:message></th>
												<th><spring:message code="access path"></spring:message></th>
												<th><spring:message code="purview description"></spring:message></th>
												<th><spring:message code="operation"></spring:message></th>
											</tr>
										</thead>

										<tbody>
											<c:forEach items="${list.resultList}" var="item"
												varStatus="status">
												<tr class="odd gradeX">

													<td>${item.spurname }</td>
													<td>${item.surlpath }</td>
													<td>${item.sdescription }</td>

													<td><a href="#"
														onclick="toEditPurview(${item.sysPurviewId});"
														class="btn mini blue"><spring:message
																code="btn.common.edit"></spring:message></a> <a
														onclick="delPurviews(${item.sysPurviewId},'${item.spurname}');"
														href="#" class="btn mini red"><spring:message
																code="btn.common.delete"></spring:message></a></td>
												</tr>
											</c:forEach>
										</tbody>
									</table>
									<!-- 分页 -->
									<c:if test="${list.totalPages>1}">
										<div class="pagination" style="float: right">
											<ul>
												<li><a href="javascript:void();"><spring:message
															code="total"></spring:message>：${list.totalRows}</a></li>
												<li
													<c:if test="${list.currentPage==1}">class="disabled"</c:if>>
													<c:if test="${list.currentPage>1}">
														<a href="javascript:toListPage(${list.currentPage-1});"><spring:message
																code="previous page"></spring:message></a>
													</c:if> <c:if test="${list.currentPage==1}">
														<a href="#"><spring:message code="previous page"></spring:message></a>
													</c:if>
												</li>
												<c:forEach begin="1" end="${list.totalPages}" var="item">
													<c:if
														test="${item < 4 || item==list.currentPage || item==list.currentPage+1 || item==list.currentPage+2 || item + 3 > list.totalPages }">
														<li
															<c:if test="${list.currentPage==item }">class="active"</c:if>><a
															href="javascript:toListPage(${item});">${item}</a></li>
													</c:if>
												</c:forEach>
												<li
													<c:if test="${list.currentPage==list.totalPages}">class="disabled"</c:if>>
													<c:if test="${list.currentPage==list.totalPages}">
														<a href="#"><spring:message code="next page"></spring:message>
														</a>
													</c:if> <c:if test="${list.currentPage!=list.totalPages}">
														<a href="javascript:toListPage(${list.currentPage+1})"><spring:message
																code="next page"></spring:message> </a>
													</c:if>
												</li>
											</ul>
										</div>
									</c:if>
								</div>
							</div>

						</div>

					</div>


				</div>
			</div>

		</form>
		<!-- to 新增或编辑页面--子菜单:权限  列表的menuId,menParentId带过去-->
		<form id="to_form" action="<%=request.getContextPath() %>/sys/menu-purview/form" method="post">
									<input type="hidden" id="to_form_menuid" name="id"/><!-- syspurview主键id -->
									<input type="hidden" id="menuid" name="menuId" value="${menuId}"/>
									<input type="hidden" name="menParentId" value="${menParentId }"/>
		</form>
</body>
</html>